//
//  XWTestSetStyleVC.m
//  XWSegmentedControlTest
//
//  Created by wzl on 2017/3/20.
//  Copyright © 2017年 亮哥. All rights reserved.
//

#import "XWTestSetStyleVC.h"
#import <XWSegmentedControl/XWSegmentedControl.h>

@interface XWTestSetStyleVC ()<XWSegmentedControlDelegate>
@property (nonatomic,strong) XWSegmentedControl *mySegmentCtrl1;
@property (nonatomic,strong) XWSegmentedControl *mySegmentCtrl2;
@property (nonatomic,strong) XWSegmentedControl *mySegmentCtrl3;
@property (nonatomic,strong) XWSegmentedControl *mySegmentCtrl4;
@end

@implementation XWTestSetStyleVC
#pragma mark - 父类方法
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"样式设置";
    [self.view addSubview:self.mySegmentCtrl1];
    [self.view addSubview:self.mySegmentCtrl2];
    [self.view addSubview:self.mySegmentCtrl3];
    [self.view addSubview:self.mySegmentCtrl4];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}

#pragma mark - 私有方法
-(XWSegmentedControl *)mySegmentCtrl1{
    if (_mySegmentCtrl1 == nil) {
        _mySegmentCtrl1 = [[XWSegmentedControl alloc] initWithFrame:CGRectMake(0, 94, [UIScreen mainScreen].bounds.size.width, 40)];
        _mySegmentCtrl1.delegate = (id)self;
        NSArray *titles = @[@"测试1",@"测试2",@"测试3",@"测试4"];
        [_mySegmentCtrl1 setSegmentedControlTitles:titles andViews:nil];
        //设置是否有标题下划线、中间间隔线
        _mySegmentCtrl1.isHasTitleBottomLine = NO;
        _mySegmentCtrl1.isHasTitleCenterLine = YES;
    }
    
    return _mySegmentCtrl1;
}

-(XWSegmentedControl *)mySegmentCtrl2{
    if (_mySegmentCtrl2 == nil) {
        _mySegmentCtrl2 = [[XWSegmentedControl alloc] initWithFrame:CGRectMake(0, 144, [UIScreen mainScreen].bounds.size.width, 40)];
        _mySegmentCtrl2.delegate = (id)self;
        NSArray *titles = @[@"短",@"标题很长",@"标题非常非常长"];
        [_mySegmentCtrl2 setSegmentedControlTitles:titles andViews:nil];
        //设置线条样式
        _mySegmentCtrl2.lineStyle = XWSegmentedControlLineStyleEqualTitle;
    }
    
    return _mySegmentCtrl2;
}

-(XWSegmentedControl *)mySegmentCtrl3{
    if (_mySegmentCtrl3 == nil) {
        _mySegmentCtrl3 = [[XWSegmentedControl alloc] initWithFrame:CGRectMake(0, 194, [UIScreen mainScreen].bounds.size.width, 40)];
        _mySegmentCtrl3.delegate = (id)self;
        _mySegmentCtrl3.backgroundColor = [UIColor greenColor];
        NSArray *titles = @[@"测试1",@"测试2",@"测试3",@"测试4"];
        [_mySegmentCtrl3 setSegmentedControlTitles:titles andViews:nil];
        
        //设置字体和颜色
        NSDictionary *selectedTextAttributes = @{
                                                 NSFontAttributeName : [UIFont boldSystemFontOfSize:17],
                                                 NSForegroundColorAttributeName : [UIColor whiteColor]
                                                 };
        NSDictionary *unselectedTextAttributes = @{
                                                   NSFontAttributeName : [UIFont boldSystemFontOfSize:17],
                                                   NSForegroundColorAttributeName : [UIColor redColor]
                                                   };
        [_mySegmentCtrl3 setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];
        [_mySegmentCtrl3 setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
        
        //设置选中和未选中颜色
        _mySegmentCtrl3.normalLineColor = [UIColor blueColor];
        _mySegmentCtrl3.selectLineColor = [UIColor redColor];
        
    }
    
    return _mySegmentCtrl3;
}

-(XWSegmentedControl *)mySegmentCtrl4{
    if (_mySegmentCtrl4 == nil) {
        _mySegmentCtrl4 = [[XWSegmentedControl alloc] initWithFrame:CGRectMake(0, 244, [UIScreen mainScreen].bounds.size.width, 40)];
        _mySegmentCtrl4.delegate = (id)self;
        NSArray *titles = @[@"测试1",@"测试2",@"测试3",@"测试4"];
        [_mySegmentCtrl4 setSegmentedControlTitles:titles andViews:nil];
        _mySegmentCtrl4.isHasTitleCenterLine = YES;
        //设置选中和未选中颜色
        _mySegmentCtrl4.normalLineColor = [UIColor blueColor];
        _mySegmentCtrl4.selectLineColor = [UIColor redColor];
    }
    
    return _mySegmentCtrl4;
}

#pragma mark - XWSegmentedControlDelegate
- (void)segmentedControl:(XWSegmentedControl*)segmentedControl didSelectSegmentIndex:(NSInteger)segmentIndex{
    NSLog(@"选中的index=%li",segmentIndex);
}
@end
